package org.darcy.controller.work;

import java.util.List;

import org.darcy.entity.WorkRole;
import org.darcy.entity.WorkRoleUser;
import org.darcy.framework.model.R;
import org.darcy.service.work.WorkRoleService;
import org.darcy.service.work.WorkRoleUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

@Tag(name = "WorkRole接口：业务流程角色")
@RestController
@RequestMapping(value = "/WorkRole")
@Slf4j
public class WorkRoleController {

	private final String info_prefix = "[业务流程角色模块]";

	@Autowired
	private WorkRoleService WorkRoleService;

	@Autowired
	private WorkRoleUserService WorkRoleUserService;

	@Operation(summary = "所有业务流程角色")
	@PostMapping(value = "getAllRole")
	public R getAllRole() {
		List<WorkRole> data = WorkRoleService.getList();
		return R.ok().data(data);
	}

	@Operation(summary = "业务流程角色用户列表")
	@PostMapping(value = "list")
	public R list() {
		log.debug("{}-列表数据", info_prefix);
		List<WorkRoleUser> data = WorkRoleUserService.getList();
		return R.ok().data(data);
	}

	@Operation(summary = "流程角色对应用户详情")
	@GetMapping("/view/{id}")
	public R view(@PathVariable Integer id) {
		WorkRoleUser data = WorkRoleUserService.getById(id);
		return R.ok().data(data);
	}

	@Operation(summary = "新增流程角色对应用户")
	@PostMapping("add")
	public R add(@RequestBody WorkRoleUser record) {
		WorkRoleUserService.insert(record);
		return R.ok("新增成功").data(record);
	}

	@Operation(summary = "根据ID删除流程角色对应用户")
	@PostMapping("/del/{id}")
	public R del(@PathVariable Integer id) {
		WorkRoleUserService.delete(id);
		return R.ok("删除成功");
	}

	@Operation(summary = "更新流程角色对应用户")
	@PostMapping("update")
	public R update(@RequestBody WorkRoleUser record) {
		WorkRoleUserService.update(record);
		return R.ok("更新成功");
	}

}
